package com.maun.maun;

import com.maun.exception.MarshalerException;
import com.maun.exception.UnknownMarshalerTypeException;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

/**
 * 
 * @author Aleksandra Rogozhnikova, rogoznikova.av@gmail.com
 */
public final class MaunFactory {

    ////////////////////////////////////////////////////////////////////////////////////////////////
    // Static

    public static Maun getInstance(
            final String type,
            final Properties properties) throws MarshalerException {

        if (type.equals(MAUN_MYSQL)) {
            return new MaunMySql(properties);
        } else {
            final StringBuilder supportedTypes = new StringBuilder();
            for (int i = 0; i < SUPPORTED_TYPES.size(); i++) {
                supportedTypes.append("'").append(SUPPORTED_TYPES.get(i)).append("'");

                if (i < SUPPORTED_TYPES.size() - 1) {
                    supportedTypes.append(", ");
                }
            }

            throw new UnknownMarshalerTypeException(
                    "The given marshaler type, '" + type + "', is not recognized. "
                  + "The supported types are: " + supportedTypes + ".");
        }
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////
    // Instance

    private MaunFactory(
            ) {

        // Does nothing.
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////
    // Constants

    public static final String MAUN_MYSQL = "mysql";

    private static final List<String> SUPPORTED_TYPES = Arrays.asList(new String[]{
        MAUN_MYSQL,
    });

}